/**
 * Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hengtiansoft.lfy.chart.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.hengtiansoft.lfy.base.BaseActivity;
import com.hengtiansoft.lfy.chart.applib.controller.HXSDKHelper;
import com.hengtiansoft.lfy.chart.DemoHXSDKHelper;
import com.hengtiansoft.lfy.R;
import com.hengtiansoft.lfy.chart.adapter.NewFriendsMsgAdapter;
import com.hengtiansoft.lfy.constants.Constants;
import com.hengtiansoft.lfy.chart.db.InviteMessgeDao;
import com.hengtiansoft.lfy.chart.domain.InviteMessage;

import java.util.List;

/**
 * 申请与通知
 *
 */
public class NewFriendsMsgActivity extends BaseActivity {
    private ListView listView;
    private Context mContext;
    private NewFriendsMsgAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.activity_new_friends_msg);
        listView = (ListView) findViewById(R.id.list);
        InviteMessgeDao dao = new InviteMessgeDao(this);
        List<InviteMessage> msgs = dao.getMessagesList();
        // 设置adapter
        adapter = new NewFriendsMsgAdapter(this, 1, msgs);
        listView.setAdapter(adapter);
        ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList()
                .get(Constants.NEW_FRIENDS_USERNAME).setUnreadMsgCount(0);
        listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                if (((DemoHXSDKHelper) HXSDKHelper.getInstance())
                        .getContactList()
                        .containsKey(adapter.getItem(position).getFrom())) {
                    Intent intent = new Intent();
                    intent.setClass(mContext, PersonalDetailsActivity.class);//点击跳转用户详细页面
                    intent.putExtra("username",
                            adapter.getItem(position).getFrom());
                    intent.putExtra("type", "send");
                    mContext.startActivity(intent);
                    // startActivity(new Intent(
                    // GroupDetailsActivity.this,
                    // ChatActivity.class).putExtra(
                    // "userId", username));
                } else {
                    Intent intent = new Intent();
                    intent.setClass(mContext, PersonalDetailsActivity.class);
                    intent.putExtra("username",
                            adapter.getItem(position).getFrom());
                    intent.putExtra("type", "add");
                    mContext.startActivity(intent);
                }
            }
        });

    }

    public void back(View view) {
        finish();
    }

}
